<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon
      :icon-class="isFull ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="toggleScreen"
    />
  </div>
</template>

<script>
import sf from 'screenfull'
export default {
  name: 'ScreenFull',
  data () {
    return {
      isFull: false
    }
  },
  created () {
    this.watchScreen()
  },
  destroyed () {
    sf.off('change')
  },
  methods: {
    toggleScreen () {
      if (!sf.isEnabled) {
        return this.$message.error('您的浏览器不支持全屏功能')
      }
      sf.toggle()
    },
    watchScreen () {
      sf.on('change', () => {
        this.isFull = sf.isFullscreen
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
